<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>采集设置</legend>
        </fieldset>

        <form class="layui-form" action="" >
            <div class="layui-form-item">
                <label class="layui-form-label">客户端id</label>
                <div class="layui-input-block">
                    <input type="text" name="client_id" lay-verify="required" lay-reqtext="客户端id是必填项，不能为空" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">客户端类型</label>
                <div class="layui-input-block">
                    <select name="client_type" lay-filter="aihao">
                        <option value="2"></option>
                        <option value="0">机器名</option>
                        <option value="1" selected="">MAC地址</option>
                        <option value="2" selected="">IP地址</option>
                    </select>
                </div>
            </div>
			
			<div class="layui-form-item">
        
                <div class="layui-inline">
                    <label class="layui-form-label">验证日期</label>
                    <div class="layui-input-inline">
                        <input type="text" name="date" id="date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                    </div>
                </div>
               
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="send_collect">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>

    </div>
</div>

<script src="../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../js/common.js" charset="utf-8"></script>
<script src="../js/base.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['form', 'layedit', 'laydate', 'myModule'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , myModule = layui.myModule;

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

        //自定义验证规则
        form.verify({
            title: function (value) {
                if (value.length < 5) {
                    return '标题至少得5个字符啊';
                }
            }
            , pass: [
                /^[\S]{6,12}$/
                , '密码必须6到12位，且不能出现空格'
            ]
            , content: function (value) {
                layedit.sync(editIndex);
            }
        });
      

        //监听提交
        form.on('submit(send_collect)', function (data) {
			
			console.log(JSON.stringify(data))
			var indAjax = layer.load(0, {
                      shade: [0.1, '#000']
                  });
                  
                  console.log(JSON.stringify(data.field))
                  //ajax请求
                  myModule.ajax({
                          url: `${ajaxUrlSet}/sendcollect`,
                          type: "Post",
                          dataType: "json",
                          data: JSON.stringify(data.field),
                          success: function(res) {
                            layer.msg('请求成功', {icon: 1,time: 1100});
                            layer.close(indAjax); 
                          },
                          error:function(r){
                            layer.msg('请求失败', {icon: 2,time: 1100});
                            layer.close(indAjax); 
                          }
                      })

                  return false;
			  
        });


    });
</script>

</body>
</html>